function ajaxRequest(url,method,parameters,onSuccess,onFailure) {

    function getMethod(method) {
        if ( typeof method != "string" )
            throw method + ": bad method (choose 'GET' or 'POST')";
        method = method.trim().toLowerCase();
        if ( method != 'get' && method != 'post' )
            throw method + ": bad method (choose 'GET' or 'POST')";
        return method;
    }

    function getParameters(method,parameters) {
        if ( typeof parameters != "object" )
            throw method + ": bad parameters (must be an object)";
        if ( method === "get") {
            var params = [];
            for ( param in parameters ){
                if(parameters[params] instanceof Array === false)
                    params.push(param + "=" + encodeURIComponent(parameters[param]));
                else{
                    params.push(param+"[]="+encodeURIComponent(parameters[param]));
                }
            }

            return params.join("&");
        }
        else {
            var params = new FormData();
            for ( param in parameters ) {
                params.append(param,parameters[param]);
            }
            return params;
        }
    }

    method = getMethod(method);

    var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

    if ( onSuccess && onFailure ) {
        xmlhttp.onload = onSuccess;
        xmlhttp.onerror = onFailure;
    }

    if ( method === 'get' ) {
        if ( parameters == "" )
            xmlhttp.open("GET",url,true);
        else
            xmlhttp.open("GET",url + "?" + getParameters("get",parameters),true);
        xmlhttp.send();
    }
    else {
        xmlhttp.open("POST",url,true);
        xmlhttp.send(getParameters("post",parameters));
    }
}